﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CncConvProg.Geometry;
using CncConvProg.Geometry.Entity;
using CncConvProg.Model.ConversationalStructure.Lavorazioni.Common;

namespace CncConvProg.Model.ConversationalStructure.Lavorazioni.Fresatura.Pattern
{
    [Serializable]
    public class RettangoloPattern : IMillingPattern
    {
        public double LivelloZ { get; set; }

        public double Larghezza { get; set; }

        public double Altezza { get; set; }

        public double PuntoStartX { get; set; }

        public double PuntoStartY { get; set; }

        public SquareShapeHelper.SquareShapeStartPoint StartPoint { get; set; }

        public Profile2D GetClosedProfile()
        {
            var p = new Profile2D();

            
            var centerPoint = SquareShapeHelper.GetCenterPoint(StartPoint, PuntoStartX, PuntoStartY, Larghezza, Altezza);

            var l1 = new Line2D
            {
                Start = new Point2D
                {
                    X = centerPoint.X + Larghezza / 2,
                    Y = centerPoint.Y + Altezza / 2,
                },

                End = new Point2D
                {
                    X = centerPoint.X + Larghezza / 2,
                    Y = centerPoint.Y - Altezza / 2,
                }
            };

            var l2 = new Line2D
            {
                Start = l1.End,

                End = new Point2D
                {
                    X = centerPoint.X - Larghezza / 2,
                    Y = centerPoint.Y - Altezza / 2,
                }
            };

            var l3 = new Line2D
            {
                Start = l2.End,

                End = new Point2D
                {
                    X = centerPoint.X - Larghezza / 2,
                    Y = centerPoint.Y + Altezza / 2,
                }
            };

            var l4 = new Line2D
            {
                Start = l3.End,
                End = l1.Start,
            };

            p.AddEntity(l1);
            p.AddEntity(l2);
            p.AddEntity(l3);
            p.AddEntity(l4);
            
            p.SetPlotStyle();
            return p;

        }
    }
}